from flask import render_template,request
from flask.views import MethodView

from pro_name.user import user_bp
from pro_name.models import User

class LoginView(MethodView):
    def _jump(self,msg = None):
        return render_template('wtf3_login.html',msg = msg)
        
    def get(self,msg = None):
        return self._jump()

    def post(self):
        uname = request.form.get('name')
        pwd = request.form.get('pwd')
        user = User.query.filter(User.name ==uname,User.pwd == pwd).first()
        if user:
            return '登录成功！'
        else:
            return self._jump(msg='登录的用户名或密码错误')

user_bp.add_url_rule('/login/',view_func=LoginView.as_view('login'))